package com.wk.pms.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wk.common.bean.Resp;
import com.wk.pms.entity.SkuInfo;
import com.wk.pms.service.SkuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/skuinfo")
public class SkuInfoController {

    @Autowired
    private SkuInfoService skuInfoService;

    @GetMapping("/info/{skuId}")
    public Resp<SkuInfo> info(@PathVariable("skuId") Long skuId){
        SkuInfo skuInfo = skuInfoService.getById(skuId);
        return Resp.ok(skuInfo);
    }
    
    /**
     * 根据spuId查询对应的sku信息
     */
    @GetMapping("{spuId}")
    public Resp<List<SkuInfo>> queryBySpuId(@PathVariable Long spuId){
        return Resp.ok(skuInfoService.list(new QueryWrapper<SkuInfo>().eq("spu_id", spuId)));
    }
}

